package yhao.infra.feature.qiniu.oss.core;

import com.qiniu.common.Zone;
import com.qiniu.util.Auth;
import org.apache.commons.lang3.StringUtils;

/**
 * @author yoara
 * <p> Created on 2019/6/6 </p>
 */
public class BucketInfo {
    private String name;
    private String url;
    private Zone zone;
    private Auth auth;
    private String prefix = "";

    public BucketInfo(String accessKey,String secretKey,String name, String url, String zone) {
        if (StringUtils.isBlank(name)) {
            throw new RuntimeException("七牛图片组件需要bucket的name");
        }
        if (StringUtils.isBlank(url)) {
            throw new RuntimeException("七牛图片组件需要bucket的url");
        }
        if (StringUtils.isBlank(zone)) {
            throw new RuntimeException("七牛图片组件需要bucket的zone");
        }
        if (StringUtils.isBlank(accessKey)) {
            throw new RuntimeException("七牛图片组件需要bucket的accessKey");
        }
        if (StringUtils.isBlank(secretKey)) {
            throw new RuntimeException("七牛图片组件需要bucket的secretKey");
        }
        auth = Auth.create(accessKey, secretKey);
        this.name = name;
        this.url = url;
        switch (zone.toLowerCase()) {
            case "huabei":
                this.zone = Zone.huabei();
                break;
            case "huadong":
                this.zone = Zone.huadong();
                break;
            case "huanan":
                this.zone = Zone.huanan();
                break;
            case "beimei":
                this.zone = Zone.beimei();
                break;
            case "xinjiapo":
                this.zone = Zone.zoneAs0();
                break;
            default:
                this.zone = Zone.autoZone();
                break;
        }
    }

    public String getPrefix() {
        return prefix;
    }

    public void setPrefix(String prefix) {
        this.prefix = prefix;
    }

    public String getName() {
        return name;
    }

    public String getUrl() {
        return url;
    }

    public Zone getZone() {
        return zone;
    }

    public Auth getAuth() {
        return auth;
    }
}
